package patterns.flyweight;

/**
 * Created by lenovo on 2016/11/28 0028.
 * 演示享元模式的调用
 */
public class FlyweightPatternDemo {
    private static final String[] colors = {"Red", "Blue", "Yellow", "Green"};

    public static void main(String[] args) {
        //绘制
        for (int i = 0; i < 9; ++i) {
            Circle circle = (Circle) ShapeFactory.getCircle(getRandomColor());
            circle.setRadius(100);
            circle.setX((int) (Math.random() * 100));
            circle.setY((int) (Math.random() * 100));
            circle.draw();
        }
    }

    public static String getRandomColor() {
        return colors[(int) (Math.random() * colors.length)];
    }
}
